-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Conversation
$filter = new InputFilter(); | ||
$filter->add($this->object->getInputFilter(), $name); | ||
$this->filter = $filter; | ||
if (null === $this->filter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bugfix: dupe filters being added on multiple calls to getInputFilter().
Really good work ! This was really missing. I've quickly read the source, it seems good to me. I wonder about one thing : when hydrated, what will the element contain ? the file name ? |
@bakura10 When hydrated, the element's value "should" contain a string of the file path. I need to test this though - thanks for bringing it up. |
I really like this new approach. Having the FileInput as part of InputFilter makes a lot of sense to me, and I appreciate how much it simplifies the validators. Looks like you may need to rebase off of develop, btw. Keep me posted, and let me know when it's ready to review for merge! |
Thanks @weierophinney. I'll pick this back up and ping you when it's ready for a final review. |
I've been thinking about this too, but haven't come up with a generic/configurable/automatic way to do this with the form yet. There seemed to be several use cases one may want to do in this situation, so in an effort to get this out and tested, we'll leave it up to the developer to do their own custom handling for now. File validations and filters will still run and process the file. But, it will be up to the developer to explicitly check that the file element is valid after postback and then modify the form/view to compensate, update the db, etc.. In some cases you might be able to separate out the file uploads into their own form to get around this, but not always. |
What about using event ? Envoyé de mon iPhone Le 3 oct. 2012 à 16:14, Chris Martin notifications@github.com a écrit :
|
This is ready for a final review. Thanks! |
It will be fantastic to have this merged for 2.1! I almost don't dare to ask, but what about docs? It would be nice when this gets merged, the docs can be merged directly too. |
Wow... you need such an awesome work @cgmartin ! That's outstanding ! I can't wait to try this out ! |
@juriansluiman yes, already planning to work on the docs after this gets a final approval. I wouldn't leave you hanging like that! ;) Currently working on usage examples to see if this could fit with the postRequestGet plugin somehow. @bakura10 thanks! |
First +1 for you! Thanks Op 6 okt. 2012 om 16:15 heeft Chris Martin notifications@github.com het volgende geschreven:
|
Found an issue when using the HTML5 "multiple" attribute with the file element. Working on a fix. Do not merge. |
OK this should be good for a final review again. A "nice-to-have" would be an Explode Filter, akin to the Explode validators when the multiple attribute is set. IMO, I don't think that should hold up this PR, but I'll work on getting it in regardless. @basz yep, working on it. We'll see how it goes. |
A few questions as we are currently using the existing implementation, will we still be able to achieve all the functionality as shown in the following gist? https://gist.github.com/83f582c74d45174e0538, for example;
Anything else you can see in there that might not work? |
@cgmartin Can you rebase against latest develop? There are evidently conflicts currently, and I don't want to mess up the merge. Thanks! |
…to Zend/Progressbar/Upload/UploadHandlers
@davidwindell you'll still be able to achieve those things, though the implementation will be different, obviously. The FileSize, Extension, MimeType validators still exist; Count would now be managed by a Collection; and the destination can be specified via the RenameUpload filter. Getting the mime info for your attachment looks to be the only difference - You would likely use @weierophinney, rebased. Thanks! Now that ZendCon is over I'll be picking back up on the docs and the following enhancements in the following week: Post-Redirect-Get plugin support Multi-File Filtering |
Travis failed only on 5.3.3 tests due to network connectivity, see details. Latest commit should pass. Added a new Post-Redirect-Get plugin for File upload forms: It is fundamentally different than the original plugin as it will process the form on POST and save any form errors in the session when it comes back around on the GET. Usage is different, see example here: https://github.com/cgmartin/ZF2FileUploadExamples/blob/master/src/ZF2FileUploadExamples/Controller/Examples.php#L75 |
… to match PostRedirectGet plugin
STELLAR work, @cgmartin !!!! |
Can't wait to use that ! Thank you @cgmartin ! |
👍 👏 🤘 whohoo! |
Thanks, @weierophinney. It's neat that it was able to fit into your Form/InputFilter design. Designing Beautiful Software, indeed! ;) Still working on the examples and docs. And I'll make a separate PR for the Explode filter. On Nov 6, 2012, at 3:11 PM, weierophinney notifications@github.com wrote:
|
@cgmartin , is it possible to create an InputFilter for file upload using InputFactory? I tried different variant like this. but all failed. $factory = new InputFactory();
$this->add($factory->createInputFilter(array(
'name' => 'file',
'required' => true,
))); |
@mbn18 , pretty sure it's possible by adding a https://github.com/zendframework/zf2/blob/master/library/Zend/Form/Element/File.php#L62 |
@cgmartin , tried that with no success. I think that type is not the problem as it is already being declared at: I tried that but got an error. $this->add($factory->createInputFilter(array(
'name' => 'file',
'required' => true,
'type' => 'Zend\InputFilter\FileInput',
)));
Maybe the class is not defined yet or not compatible? |
Ah, we both may have confused by the differences between InputFilter vs. Input. Assuming $this->add($factory->createInput(array(
'name' => 'file',
'required' => true,
'type' => 'Zend\InputFilter\FileInput',
))); The InputFilter acts as a parent collection of Input objects (and potentially other InputFilters). The Input objects themselves contain the The File Element utilizes $factory->createInput() rather than $factory->createInputFilter(). Here is the correct place where that type is checked in the factory: The file elements need a special Hope this helps, let us know if still encountering a problem. |
Hi @cgmartin , Here is the full version ( without other fields ) <?php
namespace WhatEver\Form;
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
class AmazingWonderfulFilter extends InputFilter
{
public function __construct()
{
$factory = new InputFactory();
$this->add($factory->createInput(array(
'name' => 'file',
'required' => true,
'type' => 'Zend\InputFilter\FileInput',
)));
} // End of __construct
} And the output ( I get the same error with and without declaring type )
|
@mbn18 what does your view script look like? |
The view script is quite big. The relevant lines are: <?php echo $this->formLabel($update_activity_rev_form->get('file')); ?>
<?php echo $this->formInput($update_activity_rev_form->get('file')->setAttributes(array('style'=>'margin-left: 10px;'))); ?> But the error occur when I run an update controller (no view) The form spec is: <?php
namespace WhatEver\Form;
use Zend\Form\Factory as FormFactory;
use Zend\Form\Form;
class UpdateFooForm extends Form
{
public function __construct()
{
parent::__construct($name);
$factory = new FormFactory();
$this->add($factory->createElement(array(
'name' => 'file',
'type' => 'Zend\Form\Element\File',
'options' => array(
'label' => 'Upload:',
),
)));
}
} |
Why aren't you using the formFile() helper? On Friday, March 15, 2013, mbn18 wrote:
Matthew Weier O'Phinney |
/me thanks @weierophinney for suggesting a view helper I did not know about :-) |
@mbn18 @weierophinney Yep, that's why I wanted to see your view, just swap out the formInput with formFile or even formRow and you're good. |
Yep, that was the problem. Thanks everyone. |
The docs I created back in the 2.1 release have some details: Feel free to open a PR against the ZF2 Docs repo if they could use any enhancements: |
File validation for forms, with PRG support Close zendframework/zendframework#2439
File validation for forms, with PRG support Close zendframework/zendframework#2439
File validation for forms, with PRG support Close zendframework/zendframework#2439
File validation for forms, with PRG support Close zendframework/zendframework#2439
File validation for forms, with PRG support Close zendframework/zendframework#2439
This PR refactors File Uploads to use Zend\Form's normal input filtering rather then using Zend\File\Transfer.
Ready to merge
Notes:
Important to note: You must be cognizant to pass the $_FILES info into the Form:
Full usage example here:
https://gist.github.com/3797983